package br.com.bafonline.controller.ajax;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import br.com.bafonline.model.business.AlbumBO;
import br.com.bafonline.model.business.FigurinhaBO;
import br.com.bafonline.model.dto.AlbumDTO;
import br.com.bafonline.model.dto.FigurinhaDTO;
import br.com.bafonline.model.dto.FigurinhaUsuarioDTO;
import br.com.bafonline.model.dto.UsuarioDTO;
import br.com.bafonline.util.struts.action.BaseAction;
import br.com.bafonline.util.struts.action.Tokens;

/**
 * Action (View) utilizada numa requisi&ccedil;&atilde;o AJAX 
 * para retornar todas as figurinhas de um determinado &aacute;lbum.
 * @author bafonline
 *
 */
public class PesquisarFigurinhasAlbumUsuarioAction extends BaseAction {

	@Override
	public ActionForward processExecute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		String codigo = request.getParameter("codigo");
		String dr = request.getParameter("dr");
		AlbumBO albumBO = new AlbumBO();
		FigurinhaBO figurinhaBO = new FigurinhaBO();
		AlbumDTO albumDTO = albumBO.findById(new Integer(codigo));
		UsuarioDTO usuarioDTO = (UsuarioDTO) request.getSession().getAttribute(Tokens.LOGIN);

		List<FigurinhaDTO> list = albumBO.listarFigurinhasAlbum(Integer.valueOf(codigo));
		List<FigurinhaUsuarioDTO> listUsuario = figurinhaBO.recuperaFigurinhaUsuario(usuarioDTO, albumDTO, dr);

		request.setAttribute("list", list);
		request.setAttribute("listSize", new Integer(list.size()));
		request.setAttribute("listUsuario", listUsuario);
		request.setAttribute("listUsuarioSize", new Integer(listUsuario.size()));

		return mapping.findForward(SUCCESS);
	}
}
